package io.renren.modules.task.controller;

import com.github.pagehelper.PageInfo;
import io.renren.common.utils.R;
import io.renren.modules.task.model.TaskBo;
import io.renren.modules.task.model.TaskDetail;
import io.renren.modules.task.model.TaskVo;
import io.renren.modules.task.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author zhangquanshuo
 * @date 2020-11-21 17:25:31
 */
@RestController
@RequestMapping("business/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 创建任务的列表
     */
    @RequestMapping("/create-task-list")
    public R createTaskList(@RequestParam(value = "pageNum") Integer pageNum,
                            @RequestParam(value = "pageSize") Integer pageSize) {
        PageInfo<TaskVo> taskVoPageInfo = taskService.createTaskList(pageNum, pageSize);
        return R.ok().put("page", taskVoPageInfo);
    }

    /**
     * 分配给我的任务
     */
    @RequestMapping("/my-task-list")
    public R myTaskList(@RequestParam(value = "pageNum") Integer pageNum,
                        @RequestParam(value = "pageSize") Integer pageSize) {
        PageInfo<TaskVo> taskVoPageInfo = taskService.myTaskList(pageNum, pageSize);
        return R.ok().put("page", taskVoPageInfo);
    }

    /**
     * 审核任务列表
     */
    @RequestMapping("/audit-task-list")
    public R auditTaskList(@RequestParam(value = "pageNum") Integer pageNum,
                           @RequestParam(value = "pageSize") Integer pageSize) {
        PageInfo<TaskVo> taskVoPageInfo = taskService.auditTaskList(pageNum, pageSize);
        return R.ok().put("page", taskVoPageInfo);
    }

    /**
     * 任务详情信息和文件信息
     */
    @GetMapping("/task-detail/{taskId}")
    public R taskDetail(@PathVariable("taskId") Long taskId) {
        TaskDetail taskDetail = taskService.getTaskDetail(taskId);
        return R.ok().put("taskDetail", taskDetail);
    }

    /**
     * 列表(全部任务)
     */
    @RequestMapping("/list")
    //@RequiresPermissions("generator:businesstask:list")
    public R list(@RequestParam(value = "pageNum") Integer pageNum,
                  @RequestParam(value = "pageSize") Integer pageSize) {
        PageInfo<TaskVo> taskVoPageInfo = taskService.queryPage(pageNum, pageSize);
        return R.ok().put("page", taskVoPageInfo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("generator:businesstask:info")
    public R info(@PathVariable("id") Long id) {
        TaskVo taskVo = taskService.getById(id);
        return R.ok().put("data", taskVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("generator:businesstask:save")
    public R save(@RequestBody TaskBo taskBo) {
        Integer save = taskService.save(taskBo);
        if (save > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("generator:businesstask:update")
    public R update(@RequestBody TaskBo taskBo) {
        Integer update = taskService.update(taskBo);
        if (update > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("generator:businesstask:delete")
    public R delete(@RequestBody Long[] ids) {
        Integer delete = taskService.delete(ids);
        if (delete > 0) {
            return R.ok();
        }
        return R.error();
    }

}
